/***********************************************************************

Camp Assault
Mapping: Simon 'Techno2SL' Tapping
Scripting: Alex 'Sparks' Romo

***********************************************************************/

#include maps\_utility;
#include common_scripts\utility;
#include maps\camp_assault_code;

#using_animtree( "generic_human" );

main()
{
	/*--------------------
	Reflections
	----------------------*/
	if ( getdvar( "r_reflectionProbeGenerate" ) == "1" )
	{
		return;
	}

	/*--------------------
	Level Files
	----------------------*/
	SetDvar( "r_watersim_enabled", "1" );
	maps\camp_assault_fx::main();

	/*--------------------
	PreCache
	----------------------*/
	preCacheStuff();

	/*--------------------
	BattleChatter
	----------------------*/
	battlechatter_off();

	/*--------------------
	Networking
	----------------------*/
	level thread onPlayerConnect();

	/*--------------------
	Level Variables
	----------------------*/
	levelVariables();

	/*--------------------
	Flags
	----------------------*/
	flagInits();

	/*--------------------
	Threat Bias Group
	----------------------*/
	CreateThreatBiasGroup( "players" );
	CreateThreatBiasGroup( "heroes" );
	CreateThreatBiasGroup( "support" );

	/*--------------------
	Script Calls
	----------------------*/
	scriptCalls();

	/*--------------------
	Start Functions
	----------------------*/
	default_start( ::start_intro );
	add_start( "intro", ::start_intro, &"CAMPASSAULT_START_INTRO" );
	add_start( "beach", ::start_beach, &"CAMPASSAULT_START_BEACH" );

	level.custom_introscreen = ::custom_introscreen;

	/*--------------------
	Load
	----------------------*/
	maps\_load::main();

	/*--------------------
	Early Level Fix
	----------------------*/
	level.early_level[ level.script ] = false;

	/*--------------------
	Level Support
	----------------------*/
	maps\camp_assault_amb::main();
	maps\camp_assault_anim::main();
}

/***********************************************************************
Start Points
***********************************************************************/

start_intro()
{
	//setmusicstate( "INTRO" );

	setupRoebuck();
	setupPolonsky();
	setupSullivan();
	setupRedShirt1();
	setupRedShirt2();

	flag_wait ( "all_players_connected" );
	flag_wait ( "all_players_spawned" );

	thread maps\camp_assault_event1::introRide();

	players = get_players();
	for( x = 0; x < players.size; x++ )
	{
		player = players[x];
		player SetClientDvar( "hud_showStance", "0" );
		player SetClientDvar( "compass", "0" );
		player SetClientDvar( "ammoCounterHide", "1" );
		player setclientdvar( "miniscoreboardhide","1" );
		player DisableWeapons();
	}

	level waittill ( "finished final intro screen fadein" );

	level thread maps\_utility::autosave_by_name( "post_intro" );
}

start_beach()
{
	//setmusicstate( "BEACH" );

	setupRoebuck();
	setupPolonsky();
	setupSullivan();
	setupRedShirt1();
	setupRedShirt2();

	node = getNode( level.Roebuck.target, "targetname" );
	level.Roebuck Teleport( node.origin, node.angles );
	node = getNode( level.Polonsky.target, "targetname" );
	level.Polonsky Teleport( node.origin, node.angles );
	node = getNode( level.Sullivan.target, "targetname" );
	level.Sullivan Teleport( node.origin, node.angles );
	node = getNode( level.redShirt1.target, "targetname" );
	level.redShirt1 Teleport( node.origin, node.angles );
	node = getNode( level.redShirt2.target, "targetname" );
	level.redShirt2 Teleport( node.origin, node.angles );

	flag_wait ( "all_players_connected" );
	flag_wait ( "all_players_spawned" );

	players = get_players();
	for( x = 0; x < players.size; x++ )
	{
		player = players[ x ];

		beachPlayerSpot = getStruct( "beach_playerspawn_" + ( x + 1 ), "targetname" );
		assert( isDefined( beachPlayerSpot ) );

		player thread coop_warp_player( beachPlayerSpot );
	}

	thread maps\camp_assault_event1::introBeach();
}